<?php

(defined('BASEPATH')) OR exit('No direct script access allowed');

class Account_model extends CI_Model {

    public function __construct() {
        parent::__construct();
    }

    private function _set_where($param) {


        if (isset($param['id']))
            $this->db->where('id', $param['id']);
        
        if (isset($param['password']))
            $this->db->where('password', $param['password']);

        if (isset($param['email']))
            $this->db->where('email', $param['email']);
        
//        if (isset($param['fullname']))
//            $this->db->where('fullname', $param['fullname']);

        if (isset($param['active']))
            $this->db->where('active', $param['active']);
        
        if (isset($param['role']))
            $this->db->where('role', $param['role']);
    }

    function get_account($param = array()) {
        
        $this->_set_where($param);

        if (isset($param['order_by']))
            $this->db->order_by($param['order_by']);
        else
            $this->db->order_by('fullname');

        return $this->db->get('account')->result();
    }

    function get_account_array($params = array()) {
        
        $accounts = $this->get_account($params);
        
        $output = array();
        
        foreach($accounts as $item)
        {
            $output[$item->id] = $item->fullname;
        }
        return $output;
    }
    
    
}
